package study.算法;

import study.算法.工具类.Utils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @Author 刘伟涛
 * @Date 2024/3/12 15:17
 **/
public class Demo1 {
    public static void main(String[] args) {
//        List<String> list = Utils.letterCombinations("");
        List<String> list = sum("");
        System.out.println(list.size()+""+list);
    }

    public static List<String> sum(String num){
        List<String> list = new ArrayList<>();
        if(num.length() == 0){
            return list;
        }
        String[] arrs = {"","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
        sum1(list,arrs,0,num,new StringBuffer());
        return list;
    }
    public static void sum1(List<String> list,String[] arrs,int index,String num,StringBuffer stringBuffer){
        if(index == num.length()){
            list.add(stringBuffer.toString());
        }else {
            int c = Integer.parseInt(Character.toString(num.charAt(index)));
            String arr = arrs[c];
            for (int i = 0; i < arr.length(); i++) {
                stringBuffer.append(arr.charAt(i));
                sum1(list,arrs,index+1,num,stringBuffer);
                stringBuffer.deleteCharAt(index);
            }
        }
    }
}
